package com.itheima.health.h5.controller;

import com.itheima.health.dto.RoleDTO;
import com.itheima.health.dto.UserDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.Role;
import com.itheima.health.pojo.User;
import com.itheima.health.service.PermissionService;
import com.itheima.health.service.RoleService;
import com.itheima.health.service.UserExtService;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "用户模块管理")
public class UserController {
    @Reference
    private RoleService roleService;
    @Reference
    private UserExtService userExtService;
    //   开发 检查项模块   crud


    @GetMapping("user/findAll")
    public Result findAll() {
        List<Role> list = roleService.list();
        return new Result(list);
    }

    @PostMapping("user/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        Result page = userExtService.findPage(queryPageBean);
        return page;
    }

    @PostMapping("user/add")
    public Result add(@RequestBody UserDTO userDTO) {
        Boolean flag = userExtService.add(userDTO);

        return new Result(flag);
    }

    @GetMapping("user/findCheckItemIdsbyGroupId/{id}")
    public Result deleteCheckItemById(@PathVariable("id") int id){
        UserVO userVO = userExtService.findCheckItemIdsbyGroupId(id);

        return new Result(userVO);
    }

    @DeleteMapping("user/deleteById/{id}")
    public Result deleteById(@PathVariable("id") int id){
        Boolean flag = userExtService.deleteById(id);

        return new Result(flag);
    }

}

